package web

import (
	"SkyPath/internal/domain/project/constant"
	"SkyPath/internal/domain/project/entry"
	"github.com/gin-gonic/gin"
)

// 创建省级项目
func CreateProject(c *gin.Context) {
	var project constant.Projects
	if err := c.ShouldBindJSON(&project); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.CreateProjects(c, project)
}

// 创建省级下的项目条目
func CreateProjectItems(c *gin.Context) {
	var items constant.ProjectItems
	if err := c.ShouldBindJSON(&items); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.CreateProjectItem(c, items)
}

func GetProject(c *gin.Context) {
	var project constant.Projects
	entry.GetProjects(c, project)
}

func GetProjectItem(c *gin.Context) {
	var items constant.ProjectItems
	if err := c.ShouldBindJSON(&items); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.GetProjectItems(c, items)
}

// 查看条目的详情信息
func GetProjectItemDetail(c *gin.Context) {
	var items constant.ProjectItems
	if err := c.ShouldBindJSON(&items); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.GetProjectItemsDetail(c, items)
}

func ChangeProject(c *gin.Context) {
	var project constant.Projects
	if err := c.ShouldBindJSON(&project); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.ChangeProjects(c, project)
}

func ChangeProjectItem(c *gin.Context) {
	var items constant.ProjectItems
	if err := c.ShouldBindJSON(&items); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.ChangeProjectItems(c, items)
}

func DeleteProject(c *gin.Context) {
	var project constant.Projects
	if err := c.ShouldBindJSON(&project); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.DelProjects(c, project)
}

func DeleteProjectItem(c *gin.Context) {
	var items constant.ProjectItems
	if err := c.ShouldBindJSON(&items); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	entry.DelProjectItems(c, items)
}

// 查看台账
func GetLedger(c *gin.Context) {
	//var ledger constant.Ledger
	//if err := c.ShouldBindJSON(&ledger); err != nil {
	//	c.JSON(400, gin.H{"error": err.Error()})
	//	return
	//}
	entry.GetLedger(c)
}

// 获取台账表头
func GetLedgerHeaders(c *gin.Context) {
	//var ledger constant.Ledger
	//if err := c.ShouldBindJSON(&ledger); err != nil {
	//	c.JSON(400, gin.H{"error": err.Error()})
	//	return
	//}
	entry.GetLedgerHeaders(c)
}

// 获取台账表头
func ChangeLedgers(c *gin.Context) {
	var ledger map[string]interface{}
	if err := c.ShouldBindJSON(&ledger); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	//fmt.Println(ledger.TicketYears, ledger.ProjectItemsId)
	entry.ChangeLedgers(c, ledger)
}

func UploadFiles(c *gin.Context) {
	entry.UploadFiles(c)
}

func DownloadFiles(c *gin.Context) {
	entry.DownloadFiles(c)
}
